import API from './api';
import CommonJS from './common'
import * as oex from 'oex-web3'; 

 async function getAccount(accountName){
	//根据账户名查看账户信息 
	const nodeInfo = uni.getStorageSync('nodeInfo');
	//const Admin = API.admin;
	var result ;
	 oex.utils.setProvider(nodeInfo);  //设置节点rpc信息
	 oex.utils.setApp();
	 // if(accountName){
		//   const data = await  oex.account.getAccountExByName(accountName);
	 // }else{
		  
	 // }
		const data = await  oex.account.getAccountExByName(accountName); //请求参数
	 await  CommonJS.request(nodeInfo,"POST",data).then( res => {
		 //console.log(res)
		 result = res
	 }).catch(error => {
			console.log(error)
			result = error
	 })
	return result;
}

 async function getCoin(nodeInfo,assetId){
	//assetId 资产详情
	
	var result ;
	 oex.utils.setApp();
	 
	 const data = await  oex.account.getAssetInfoById(assetId); //请求参数
	 //console.log(data)
	 await  CommonJS.request(nodeInfo,"POST",data).then( res => {
		 //console.log(res)
		 result = res
	 }).catch(error => {
			console.log(error)
			result = error
	 })
	return result;
}


async function getuserInfo(data){
	var result;
	await uni.request({
		url:API.appServeApi + API.userInfo + '?i18n_language=' + uni.getStorageSync('system_info'),
		data:data
	}).then(data => {
		//data为一个数组，数组第一项为错误信息，第二项为返回数据
		var [error, res]  = data;
		result = res.data;
	})
	return result;
}
module.exports = {
	getAccount,getuserInfo,getCoin
}